package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.PmsFeightTemplate;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.PmsFeightTemplateDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface PmsFeightTemplateMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, name, chargeType, firstWeight, firstFee, continueWeight, continmeFee, dest);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(PmsFeightTemplate record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(name).equalTo(record::getName)
                  .set(chargeType).equalTo(record::getChargeType)
                  .set(firstWeight).equalTo(record::getFirstWeight)
                  .set(firstFee).equalTo(record::getFirstFee)
                  .set(continueWeight).equalTo(record::getContinueWeight)
                  .set(continmeFee).equalTo(record::getContinmeFee)
                  .set(dest).equalTo(record::getDest);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PmsFeightTemplate record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(name).equalToWhenPresent(record::getName)
                  .set(chargeType).equalToWhenPresent(record::getChargeType)
                  .set(firstWeight).equalToWhenPresent(record::getFirstWeight)
                  .set(firstFee).equalToWhenPresent(record::getFirstFee)
                  .set(continueWeight).equalToWhenPresent(record::getContinueWeight)
                  .set(continmeFee).equalToWhenPresent(record::getContinmeFee)
                  .set(dest).equalToWhenPresent(record::getDest);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<PmsFeightTemplate> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("PmsFeightTemplateResult")
    Optional<PmsFeightTemplate> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "PmsFeightTemplateResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "charge_type", property = "chargeType", jdbcType = JdbcType.INTEGER),
            @Result(column = "first_weight", property = "firstWeight", jdbcType = JdbcType.DECIMAL),
            @Result(column = "first_fee", property = "firstFee", jdbcType = JdbcType.DECIMAL),
            @Result(column = "continue_weight", property = "continueWeight", jdbcType = JdbcType.DECIMAL),
            @Result(column = "continme_fee", property = "continmeFee", jdbcType = JdbcType.DECIMAL),
            @Result(column = "dest", property = "dest", jdbcType = JdbcType.VARCHAR)
    })
    List<PmsFeightTemplate> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(PmsFeightTemplate record) {
        return MyBatis3Utils.insert(this::insert, record, pmsFeightTemplate, c ->
                c.map(name).toProperty("name")
                 .map(chargeType).toProperty("chargeType")
                 .map(firstWeight).toProperty("firstWeight")
                 .map(firstFee).toProperty("firstFee")
                 .map(continueWeight).toProperty("continueWeight")
                 .map(continmeFee).toProperty("continmeFee")
                 .map(dest).toProperty("dest")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(PmsFeightTemplate record) {
        return MyBatis3Utils.insert(this::insert, record, pmsFeightTemplate, c ->
                c.map(name).toPropertyWhenPresent("name", record::getName)
                 .map(chargeType).toPropertyWhenPresent("chargeType", record::getChargeType)
                 .map(firstWeight).toPropertyWhenPresent("firstWeight", record::getFirstWeight)
                 .map(firstFee).toPropertyWhenPresent("firstFee", record::getFirstFee)
                 .map(continueWeight).toPropertyWhenPresent("continueWeight", record::getContinueWeight)
                 .map(continmeFee).toPropertyWhenPresent("continmeFee", record::getContinmeFee)
                 .map(dest).toPropertyWhenPresent("dest", record::getDest)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsFeightTemplate> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsFeightTemplate> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsFeightTemplate> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsFeightTemplate> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, pmsFeightTemplate, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(PmsFeightTemplate record) {
        return update(c ->
                c.set(name).equalTo(record::getName)
                 .set(chargeType).equalTo(record::getChargeType)
                 .set(firstWeight).equalTo(record::getFirstWeight)
                 .set(firstFee).equalTo(record::getFirstFee)
                 .set(continueWeight).equalTo(record::getContinueWeight)
                 .set(continmeFee).equalTo(record::getContinmeFee)
                 .set(dest).equalTo(record::getDest)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(PmsFeightTemplate record) {
        return update(c ->
                c.set(name).equalToWhenPresent(record::getName)
                 .set(chargeType).equalToWhenPresent(record::getChargeType)
                 .set(firstWeight).equalToWhenPresent(record::getFirstWeight)
                 .set(firstFee).equalToWhenPresent(record::getFirstFee)
                 .set(continueWeight).equalToWhenPresent(record::getContinueWeight)
                 .set(continmeFee).equalToWhenPresent(record::getContinmeFee)
                 .set(dest).equalToWhenPresent(record::getDest)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
